Cricket.Data = {
	LiveSourceUrl: 'http://synd.cricbuzz.com/score-gadget/googuk/scores.xml',
	ResultsSourceUrl: 'http://synd.cricbuzz.com/score-gadget/googuk/results.xml',
	FixturesSourceUrl: 'http://synd.cricbuzz.com/score-gadget/googuk/schedule.xml',
	//LiveSourceUrl: 'http://gadget.essence-media.com/cricket/scores.xml',
	onLiveParsed: function() {
		Cricket.Live.load();
	},
	onResultsParsed: function() {
		Cricket.Results.load();
	},
	onFixturesParsed: function() {
		Cricket.Fixtures.load();
	},
	fetchAndParse: function() {
		_IG_FetchXmlContent(this.LiveSourceUrl+'?'+Cricket.Util.generateRandom(), this.parseLive, {refreshinterval: 1});
		_IG_FetchXmlContent(this.ResultsSourceUrl, this.parseResults);
		_IG_FetchXmlContent(this.FixturesSourceUrl, this.parseFixtures);
	},
	updateLive: function() {
		var DateNow = new Date();
		Cricket.Live.NextUpdate = DateNow.getTime() + Cricket.Live.UpdateInterval;
		_IG_FetchXmlContent(this.LiveSourceUrl+'?'+Cricket.Util.generateRandom(), this.parseLive, {refreshinterval: 1});
	},
	parseResults: function(xmldoc) {					
		if(typeof xmldoc == 'object') {
			Cricket.Results.ParsedFeed = [];
			var AllMatches = xmldoc.getElementsByTagName('match');
			for(var i = 0; i < AllMatches.length; i++) {
				var Match = new Object();
				//initialise scorecard details
				Match.ScoreCard = false;
				Match.ScoreCardLoaded = false;
				Match.ForTab = 'results';
				Match.CurrentRunRate = 0;
				Match.Teams = new Array({fullname: '', shortname: ''}, {fullname: '', shortname: ''}, {fullname: '', shortname: ''});
				
				var Team1 = AllMatches[i].getElementsByTagName('team1');
				if(Team1[0].firstChild) {
					Match.Teams[1].fullname = Team1[0].firstChild.nodeValue;
				}
				var Team1short = AllMatches[i].getElementsByTagName('team1shortName');
				if(Team1short[0].firstChild) {
					Match.Teams[1].shortname = Team1short[0].firstChild.nodeValue;
				}
				
				var Team2 = AllMatches[i].getElementsByTagName('team2');
				if(Team2[0].firstChild) {
					Match.Teams[2].fullname = Team2[0].firstChild.nodeValue;
				}
				var Team2short = AllMatches[i].getElementsByTagName('team2shortName');
				if(Team2short[0].firstChild) {
					Match.Teams[2].shortname = Team2short[0].firstChild.nodeValue;
				}
				
				//get description
				var Description = AllMatches[i].getElementsByTagName('desc');
				if(Description[0] && Description[0].firstChild) {
					Match.Description = Description[0].firstChild.nodeValue;
				}
				
				//get type
				var Type = AllMatches[i].getElementsByTagName('type');
				if(Type[0] && Type[0].firstChild) {
					Match.Type = Type[0].firstChild.nodeValue;
				}
				
				var TeamId = Match.Teams[1].shortname + Match.Teams[2].shortname;
				Match.Id = TeamId.toLowerCase();
				//get dates
				Match.Dates = {Start: '', End: ''};
				var StartDate = AllMatches[i].getElementsByTagName('startdate');
				if(StartDate[0].firstChild) {
					Match.Id += ' ' +StartDate[0].firstChild.nodeValue;
					var StartDateArray = StartDate[0].firstChild.nodeValue.split(' ');
					if(3 === StartDateArray.length) {
						var StartTimestamp = Date.parse(StartDateArray[2] + '/'+StartDateArray[0] +'/'+StartDateArray[1]);
						var StartDateObject = new Date();
						StartDateObject.setTime(StartTimestamp);
						Match.Dates.Start = StartDateObject; 
					} else {
						Match.Dates.Start = StartDate[0].firstChild.nodeValue;
					}
				} else {
					Match.Dates.Start = new Date();
				}

				var EndDate = AllMatches[i].getElementsByTagName('enddate');
				if(EndDate[0].firstChild) {
					var EndDateArray = EndDate[0].firstChild.nodeValue.split(' ');
					if(3 === EndDateArray.length) {
						var EndTimestamp = Date.parse(EndDateArray[2] + '/'+EndDateArray[0] +'/'+EndDateArray[1]);
						var EndDateObject = new Date();
						EndDateObject.setTime(EndTimestamp);
						Match.Dates.End = EndDateObject;
					} else {
						Match.Dates.End = EndDate[0].firstChild.nodeValue;
					}
				} else {
					Match.Dates.End = new Date();
				}
				
				//get Venue
				var Venue = AllMatches[i].getElementsByTagName('venue');
				if(Venue[0].firstChild) {
					Match.Venue = Venue[0].firstChild.nodeValue;
				}
				
				//get result
				Match.Result = {Status: '', WinningTeam: '', WonByRuns: '', WonByWickets: ''};
				var Result = AllMatches[i].getElementsByTagName('result');
				if(Result[0]) {
					Match.Result.Status = Result[0].getAttribute('type');
					if('abandon' == Match.Result.Status) {
						Match.Result.Status = 'Abandoned';
					}
					//get winning team
					var WinningTeam = Result[0].getElementsByTagName('winningteam');
					//find winning team
					if(WinningTeam[0].firstChild && Match.Teams[2].fullname == WinningTeam[0].firstChild.nodeValue) {
						Match.Result.WinningTeam = 2;
					}
					else if(WinningTeam[0].firstChild && Match.Teams[1].fullname == WinningTeam[0].firstChild.nodeValue) {
						Match.Result.WinningTeam = 1;
					} else {
						Match.Result.WinningTeam = 0;
					}
					
					//get won by runs
					var WonByRuns = Result[0].getElementsByTagName('wonbyruns');
					if(WonByRuns[0].firstChild) {
						Match.Result.WonByRuns = WonByRuns[0].firstChild.nodeValue;
					}
					
					//get won by wickets
					var WonByWickets = Result[0].getElementsByTagName('wonbywickets');
					if(WonByWickets[0].firstChild) {
						Match.Result.WonByWickets = WonByWickets[0].firstChild.nodeValue;
					}
				}
				
				//get series
				var Series = AllMatches[i].getElementsByTagName('series');
				if(Series[0].firstChild) {
					Match.Series = Series[0].firstChild.nodeValue;
				}
				
				//get detailed scores
				var Details = AllMatches[i].getElementsByTagName('detailed-scores');
				if(Details[0] && Details[0].firstChild) {
					Match.Details = Details[0].firstChild.nodeValue;
				} else {
					Match.Details = '';
				}
				//more info
				var MoreInfo = AllMatches[i].getElementsByTagName('result-url');
				if(MoreInfo[0] && MoreInfo[0].firstChild) {
					Match.MoreInfo = MoreInfo[0].firstChild.nodeValue;
				} else {
					Match.MoreInfo = '';
				}
				
				Cricket.Results.ParsedFeed.push(Match);
				
			}
			
			Cricket.Data.onResultsParsed();
			
		} else {
			Cricket.Results.loadError();
		}
	},
	parseFixtures: function(xmldoc) {
		if(typeof xmldoc == 'object') {
			Cricket.Fixtures.ParsedFeed = [];
			var AllMatches = xmldoc.getElementsByTagName('match');
			for(var i = 0; i < AllMatches.length; i++) {
				var Match = new Object();
				//initialise scorecard details
				Match.ScoreCard = false;
				Match.ScoreCardLoaded = false;
				Match.ForTab = 'fixtures';
				//for current run rate
				Match.CurrentRunRate = 0;
				Match.Teams = new Array({fullname: '', shortname: ''}, {fullname: '', shortname: ''}, {fullname: '', shortname: ''});
				
				var Team1 = AllMatches[i].getElementsByTagName('team1');
				if(Team1[0].firstChild) {
					Match.Teams[1].fullname = Team1[0].firstChild.nodeValue;
				}
				var Team1short = AllMatches[i].getElementsByTagName('team1shortName');
				if(Team1short[0].firstChild) {
					Match.Teams[1].shortname = Team1short[0].firstChild.nodeValue;
				}
				
				var Team2 = AllMatches[i].getElementsByTagName('team2');
				if(Team2[0].firstChild) {
					Match.Teams[2].fullname = Team2[0].firstChild.nodeValue;
				}
				var Team2short = AllMatches[i].getElementsByTagName('team2shortName');
				if(Team2short[0].firstChild) {
					Match.Teams[2].shortname = Team2short[0].firstChild.nodeValue;
				}
				
				//get description
				var Description = AllMatches[i].getElementsByTagName('desc');
				if(Description[0] && Description[0].firstChild) {
					Match.Description = Description[0].firstChild.nodeValue;
				}
				
				//get type
				var Type = AllMatches[i].getElementsByTagName('type');
				if(Type[0].firstChild) {
					Match.Type = Type[0].firstChild.nodeValue;
				}
				var TeamId = Match.Teams[1].shortname + Match.Teams[2].shortname;
				Match.Id = TeamId.toLowerCase();
				
				//get dates
				Match.Dates = {Start: '', End: ''};
				var StartDate = AllMatches[i].getElementsByTagName('startdate');
				if(StartDate[0].firstChild) {
					Match.Id += ' ' +StartDate[0].firstChild.nodeValue;
					var StartDateArray = StartDate[0].firstChild.nodeValue.split(' ');
					if(3 === StartDateArray.length) {
						var StartTimestamp = Date.parse(StartDateArray[2] + '/'+StartDateArray[0] +'/'+StartDateArray[1]);
						var StartDateObject = new Date();
						StartDateObject.setTime(StartTimestamp);
						Match.Dates.Start = StartDateObject; 
					} else {
						Match.Dates.Start = StartDate[0].firstChild.nodeValue;
					}
				} else {
					Match.Dates.Start = new Date();
				}
				
				
				//get start time
				var StartTime = AllMatches[i].getElementsByTagName('starttimeGMT');
				if(0 < StartTime.length && typeof Match.Dates.Start == 'object') {
					var StartTimeRaw = StartTime[0].firstChild.nodeValue;
					var HoursMins = StartTimeRaw.split(':');
					Match.Dates.Start.setHours(HoursMins[0]);
					Match.Dates.Start.setMinutes(HoursMins[1]);
				}

				var EndDate = AllMatches[i].getElementsByTagName('enddate');
				if(EndDate[0].firstChild) {
					var EndDateArray = EndDate[0].firstChild.nodeValue.split(' ');
					if(3 === EndDateArray.length) {
						var EndTimestamp = Date.parse(EndDateArray[2] + '/'+EndDateArray[0] +'/'+EndDateArray[1]);
						var EndDateObject = new Date();
						EndDateObject.setTime(EndTimestamp);
						Match.Dates.End = EndDateObject;
					} else {
						Match.Dates.End = EndDate[0].firstChild.nodeValue;
					}
				} else {
					Match.Dates.End = new Date();
				}
				
				//get Venue
				var Venue = AllMatches[i].getElementsByTagName('venue');
				if(Venue[0].firstChild) {
					Match.Venue = Venue[0].firstChild.nodeValue;
				}
				
				//get series
				var Series = AllMatches[i].getElementsByTagName('series');
				if(Series[0].firstChild) {
					Match.Series = Series[0].firstChild.nodeValue;
				}
				
				//get description
				var Description = AllMatches[i].getElementsByTagName('matchdesc');
				if(Description[0].firstChild) {
					Match.Description = Description[0].firstChild.nodeValue;
				}
				
				Cricket.Fixtures.ParsedFeed.push(Match);
				
			}
			
			Cricket.Data.onFixturesParsed();
		} else {
			Cricket.Fixtures.loadError();
		}
				
	},
	parseLive: function(xmldoc) {
		if(typeof xmldoc == 'object') {
			Cricket.Live.ParsedFeed = [];
			var AllMatches = xmldoc.getElementsByTagName('match');

			for(var i = 0; i < AllMatches.length; i++) {
				var Match = new Object();
				//initialise scorecard details
				Match.ScoreCard = false;
				Match.ScoreCardLoaded = false;
				Match.ForTab = 'live';
				Match.CurrentRunRate = 0;
				//get Id
				Match.Id = AllMatches[i].getAttribute('id');
				// get teams
				Match.Teams = new Array({fullname: '', shortname: ''}, {fullname: '', shortname: ''}, {fullname: '', shortname: ''});
				
				var Team1 = AllMatches[i].getElementsByTagName('team1');
				if(Team1[0].firstChild) {
					Match.Teams[1].fullname = Team1[0].firstChild.nodeValue;
				}
				var Team1short = AllMatches[i].getElementsByTagName('team1shortName');
				if(Team1short[0].firstChild) {
					Match.Teams[1].shortname = Team1short[0].firstChild.nodeValue;
				}
				
				var Team2 = AllMatches[i].getElementsByTagName('team2');
				if(Team2[0].firstChild) {
					Match.Teams[2].fullname = Team2[0].firstChild.nodeValue;
				}
				var Team2short = AllMatches[i].getElementsByTagName('team2shortName');
				if(Team2short[0].firstChild) {
					Match.Teams[2].shortname = Team2short[0].firstChild.nodeValue;
				}
				
				//get description
				var Description = AllMatches[i].getElementsByTagName('matchdesc');
				if(Description[0] && Description[0].firstChild) {
					Match.Description = Description[0].firstChild.nodeValue;
				}
				
				//get type
				var Type = AllMatches[i].getElementsByTagName('type');
				if(Type[0].firstChild) {
					Match.Type = Type[0].firstChild.nodeValue;
				}
				
				//get State
				var State = AllMatches[i].getElementsByTagName('state');
				if(0 < State.length && State[0].firstChild) {
					Match.State = State[0].firstChild.nodeValue;
				} else {
					Match.State = '';
				}
				
				//get StatusDesc
				var StateDesc = AllMatches[i].getElementsByTagName('statusDescription');
				if(0 < StateDesc.length && StateDesc[0].firstChild) {
					Match.StateDesc = StateDesc[0].firstChild.nodeValue;
				} else {
					Match.StateDesc = Match.State;
				}
				
				//get series
				var Series = AllMatches[i].getElementsByTagName('series');
				if(Series[0].firstChild) {
					Match.Series = Series[0].firstChild.nodeValue;
				}
				
				//get dates
				Match.Dates = {Start: '', End: ''};
				var StartDate = AllMatches[i].getElementsByTagName('startdate');
				if(StartDate[0].firstChild) {
					var StartDateArray = StartDate[0].firstChild.nodeValue.split(' ');
					if(3 === StartDateArray.length) {
						var StartTimestamp = Date.parse(StartDateArray[2] + '/'+StartDateArray[1] +'/'+StartDateArray[0]);
						var StartDateObject = new Date();
						StartDateObject.setTime(StartTimestamp);
						Match.Dates.Start = StartDateObject; 
					} else {
						Match.Dates.Start = StartDate[0].firstChild.nodeValue;
					}
				}
				
				//get start time
				var StartTime = AllMatches[i].getElementsByTagName('starttimeGMT');
				if(0 < StartTime.length) {
					var StartTimeRaw = StartTime[0].firstChild.nodeValue;
					var HoursMins = StartTimeRaw.split(':');
					Match.Dates.Start.setHours(HoursMins[0]);
					Match.Dates.Start.setMinutes(HoursMins[1]);
				}

				var EndDate = AllMatches[i].getElementsByTagName('enddate');
				if(EndDate[0].firstChild) {
					var EndDateArray = EndDate[0].firstChild.nodeValue.split(' ');
					if(3 === EndDateArray.length) {
						var EndTimestamp = Date.parse(EndDateArray[2] + '/'+EndDateArray[1] +'/'+EndDateArray[0]);
						var EndDateObject = new Date();
						EndDateObject.setTime(EndTimestamp);
						Match.Dates.End = EndDateObject;
					} else {
						Match.Dates.End = EndDate[0].firstChild.nodeValue;
					}
				}
				
				//get result
				Match.Result = {Status: '', WinningTeam: '', WonByRuns: '', WonByWickets: ''};
				var Result = AllMatches[i].getElementsByTagName('result');
				if(Result[0]) {
					Match.Result.Status = Result[0].getAttribute('type');
					if('abandon' == Match.Result.Status) {
						Match.Result.Status = 'Abandoned';
					}
					//get winning team
					var WinningTeam = Result[0].getElementsByTagName('winningteam');
					//find winning team
					if(WinningTeam[0].firstChild && Match.Teams[2].fullname == WinningTeam[0].firstChild.nodeValue) {
						Match.Result.WinningTeam = 2;
					}
					else if(WinningTeam[0].firstChild && Match.Teams[1].fullname == WinningTeam[0].firstChild.nodeValue) {
						Match.Result.WinningTeam = 1;
					} else {
						Match.Result.WinningTeam = 0;
					}
					
					//get won by runs
					var WonByRuns = Result[0].getElementsByTagName('wonbyruns');
					if(WonByRuns[0].firstChild) {
						Match.Result.WonByRuns = WonByRuns[0].firstChild.nodeValue;
					}
					
					//get won by wickets
					var WonByWickets = Result[0].getElementsByTagName('wonbywickets');
					if(WonByWickets[0].firstChild) {
						Match.Result.WonByWickets = WonByWickets[0].firstChild.nodeValue;
					}
				}
				
				var CurrentScore = AllMatches[i].getElementsByTagName('currentscore');
				if(CurrentScore[0]) {
					CurrentRunRate = CurrentScore[0].getElementsByTagName('current-runrate');
					if(CurrentRunRate[0] && CurrentRunRate[0].firstChild) {
						Match.CurrentRunRate = CurrentRunRate[0].firstChild.nodeValue;
					}
				}
				
				//get detailed scores
				var Details = AllMatches[i].getElementsByTagName('detailed-scores');
				if(Details[0] && Details[0].firstChild) {
					Match.Details = Details[0].firstChild.nodeValue;
				} else {
					Match.Details = '';
				}
				
				//more info
				var MoreInfo = AllMatches[i].getElementsByTagName('scores-url');
				if(MoreInfo[0] && MoreInfo[0].firstChild) {
					Match.MoreInfo = MoreInfo[0].firstChild.nodeValue;
				} else {
					Match.MoreInfo = '';
				}
			
				//get the score card
				Cricket.Live.ParsedFeed.push(Match);
				if(i == (AllMatches.length - 1)) {
					Cricket.Data.getScoreCard(Cricket.Live, (Cricket.Live.ParsedFeed.length - 1), Cricket.Data.onLiveParsed);
				} else {
					Cricket.Data.getScoreCard(Cricket.Live, (Cricket.Live.ParsedFeed.length - 1));
				}
				
			}
			
			if(0 == AllMatches.length) {
				Cricket.Data.onLiveParsed();
			}						
		
			
		} else {
			Cricket.Live.loadError();
		}
	},
	getScoreCard: function(ForObject, MatchNum, CallBack, CallBackParams) {
		var ScoreUrl = ForObject.ParsedFeed[MatchNum].Details +'?'+Cricket.Util.generateRandom();
		var ForComparing = ForObject.ParsedFeed[MatchNum];
		//var ScoreUrl = 'http://gadget.essence-media.com/cricket/details_'+MatchNum+'.xml';
		if(ScoreUrl && '' != ScoreUrl) { 
			_IG_FetchXmlContent(ScoreUrl, function(response) {
				if(typeof response == 'object') {
					//match info
					var ScoreCard = {MatchInfo: {'MatchDay': '', Home: 0, Away: 0, Venue: '', Toss: {Winner: '', Decision: ''}, State: '', ManOfMatch: '', ManOfSeries: '', Umpires: [{FullName: '', Country: ''}, {FullName: '', Country: ''}, {FullName: '', Country: ''}]},
															CurrentScores: {MaxOvers: '',  Target: '',InningsNo: '', BatTeam: 0, BowlTeam: 0, BatTeamRuns: '', BatTeamWickets: '', BatTeamOvers: '', Revised: false, BatsMen: [{FullName: '', Runs: '', Balls: '', Fours: '', Sixes: ''}, {FullName: '', Runs: '', Balls: '', Fours: '', Sixes: ''}], Bowlers: [{FullName: '', Overs: '', Maidens: '', Runs: '',  Wickets: ''}, {FullName: '', Overs: '', Maidens: '', Runs: '',  Wickets: ''}], LastWicket: {FullName: '', Runs: '', Wicket: ''}, Extras: {Byes: '', Wides: '', NoBalls: '', LegByes: '', Penalty: '', Total: ''}, RequiredRunRate: 0, CurrentRunRate: 0},
															Innings: [],
															Aggregate: [{InningsNum: [], Batsmen: [], Bowlers: [], BatsmenSorted:[], BowlersSorted: [], TotalOvers: 0, TotalRuns: 0, TotalWickets: 0 },
																		{InningsNum: [], Batsmen: [], Bowlers: [], BatsmenSorted:[], BowlersSorted: [], TotalOvers: 0, TotalRuns: 0, TotalWickets: 0 },
																		{InningsNum: [], Batsmen: [], Bowlers: [], BatsmenSorted:[], BowlersSorted: [], TotalOvers: 0, TotalRuns: 0, TotalWickets: 0 }]
					};
															
					var MatchInfo = response.getElementsByTagName('match');
					if(MatchInfo[0]) {
						//get matchday
						var MatchDay = MatchInfo[0].getElementsByTagName('matchday');
						if(MatchDay[0].firstChild) {
							ScoreCard.MatchInfo.MatchDay = MatchDay[0].firstChild.nodeValue;
						}
						
						//get Home
						var Home = MatchInfo[0].getElementsByTagName('home');
						if(Home[0].firstChild && ForComparing.Teams[2].fullname == Home[0].firstChild.nodeValue) {
							ScoreCard.MatchInfo.Home = 2;
						}
						else if(Home[0].firstChild && ForComparing.Teams[1].fullname == Home[0].firstChild.nodeValue) {
							ScoreCard.MatchInfo.Home = 1;
						} else {
							ScoreCard.MatchInfo.Home = 0;
						}
						
						//get Away
						var Away = MatchInfo[0].getElementsByTagName('away');
						if(Away[0].firstChild && ForComparing.Teams[2].fullname == Away[0].firstChild.nodeValue) {
							ScoreCard.MatchInfo.Away = 2;
						}
						else if(Away[0].firstChild && ForComparing.Teams[1].fullname == Away[0].firstChild.nodeValue) {
							ScoreCard.MatchInfo.Away = 1;
						} else {
							ScoreCard.MatchInfo.Away = 0;
						}
						
						//get venue
						var Venue = MatchInfo[0].getElementsByTagName('venue');
						if(Venue[0].firstChild) {
							ScoreCard.MatchInfo.Venue = Venue[0].firstChild.nodeValue;
						}
						
						//get State
						var State = MatchInfo[0].getElementsByTagName('state');
						if(State[0].firstChild) {
							ScoreCard.MatchInfo.State = State[0].firstChild.nodeValue;
						}
						
						//get ManOfMatch
						var ManOfMatch = MatchInfo[0].getElementsByTagName('manofmatch');
						if(ManOfMatch[0].firstChild) {
							ScoreCard.MatchInfo.ManOfMatch = ManOfMatch[0].firstChild.nodeValue;
						}
						
						//get ManOfSeries
						var ManOfSeries = MatchInfo[0].getElementsByTagName('manofseries');
						if(ManOfSeries[0].firstChild) {
							ScoreCard.MatchInfo.ManOfSeries = ManOfSeries[0].firstChild.nodeValue;
						}
						
						//get Toss
						
						var Toss = MatchInfo[0].getElementsByTagName('toss');
						if(Toss[0]) {
							//get winner
							var TossWinner = Toss[0].getElementsByTagName('winner');
							if(TossWinner[0].firstChild) {
								ScoreCard.MatchInfo.Toss.Winner = TossWinner[0].firstChild.nodeValue
							}
							
							//get decision
							var TossDecision = Toss[0].getElementsByTagName('decision');
							if(TossDecision[0].firstChild) {
								ScoreCard.MatchInfo.Toss.Decision = TossDecision[0].firstChild.nodeValue
							}
						}
						
						//get Umpires
						var Umpire1 = MatchInfo[0].getElementsByTagName('Umpire1');
						if(Umpire1[0]) {
							var FullName = Umpire1[0].getElementsByTagName('Name');
							if(FullName[0].firstChild) { 
								ScoreCard.MatchInfo.Umpires[1].FullName = FullName[0].firstChild.nodeValue;
							}
							
							var Country = Umpire1[0].getElementsByTagName('Country');
							if(Country[0].firstChild) { 
								ScoreCard.MatchInfo.Umpires[1].Country = Country[0].firstChild.nodeValue;
							}
							
						}
						
						var Umpire2 = MatchInfo[0].getElementsByTagName('Umpire2');
						if(Umpire2[0]) {
							var FullName = Umpire2[0].getElementsByTagName('Name');
							if(FullName[0].firstChild) { 
								ScoreCard.MatchInfo.Umpires[2].FullName = FullName[0].firstChild.nodeValue;
							}
							
							var Country = Umpire2[0].getElementsByTagName('Country');
							if(Country[0].firstChild) { 
								ScoreCard.MatchInfo.Umpires[2].Country = Country[0].firstChild.nodeValue;
							}
							
						}
					}
					
					/**************************/
				var Match = ForObject.ParsedFeed[MatchNum];	
				ScoreCard.CurrentScores.CurrentRunRate = Match.CurrentRunRate;
				//get current score
				var CurrentScore = response.getElementsByTagName('currentscores');
				if(CurrentScore[0]) {
					//get innings
					var Innings = CurrentScore[0].getElementsByTagName('currentinningsno');
					if(Innings[0].firstChild) {
						ScoreCard.CurrentScores.InningsNo = Innings[0].firstChild.nodeValue;
					}
					
					//get batteamname
					var BatTeam = CurrentScore[0].getElementsByTagName('batteamname');
					if(BatTeam[0].firstChild && Match.Teams[2].fullname == BatTeam[0].firstChild.nodeValue) {
						ScoreCard.CurrentScores.BatTeam = 2;
					}
					else if(BatTeam[0].firstChild && Match.Teams[1].fullname == BatTeam[0].firstChild.nodeValue) {
						ScoreCard.CurrentScores.BatTeam = 1;
					} else {
						ScoreCard.CurrentScores.BatTeam = 0;
					}
					
					
					//get bowl team
					var BowlTeam = CurrentScore[0].getElementsByTagName('bwlteamname');
					if(BowlTeam[0].firstChild && Match.Teams[2].fullname == BowlTeam[0].firstChild.nodeValue) {
						ScoreCard.CurrentScores.BowlTeam = 2;
					}
					else if(BowlTeam[0].firstChild && Match.Teams[1].fullname == BowlTeam[0].firstChild.nodeValue) {
						ScoreCard.CurrentScores.BowlTeam = 1;
					} else {
						ScoreCard.CurrentScores.BowlTeam = 0;
					}
					
					//get batteam runs
					var BatTeamRuns = CurrentScore[0].getElementsByTagName('batteamruns');
					if(BatTeamRuns[0].firstChild) {
						ScoreCard.CurrentScores.BatTeamRuns = BatTeamRuns[0].firstChild.nodeValue;
					}
					
					//get batteam wickets
					var BatTeamWickets = CurrentScore[0].getElementsByTagName('batteamwkts');
					if(BatTeamWickets[0].firstChild) {
						ScoreCard.CurrentScores.BatTeamWickets = BatTeamWickets[0].firstChild.nodeValue;
					}
					
					//get batteam overs
					var BatTeamOvers = CurrentScore[0].getElementsByTagName('batteamovers');
					if(BatTeamOvers[0].firstChild) {
						ScoreCard.CurrentScores.BatTeamOvers = BatTeamOvers[0].firstChild.nodeValue;
					}	
					
					
					//get batteam overs
					var Status = CurrentScore[0].getElementsByTagName('status');
					if(Status[0] && Status[0].firstChild) {
						ScoreCard.CurrentScores.Status = Status[0].firstChild.nodeValue;
					}
					
					//get batsmen
					var BatsMen = CurrentScore[0].getElementsByTagName('batsman');
					for(var bt = 0; bt < BatsMen.length; bt++) {
						//get full name
						var FullName = BatsMen[bt].getElementsByTagName('name');
						if(FullName[0].firstChild) {
							ScoreCard.CurrentScores.BatsMen[bt].FullName = FullName[0].firstChild.nodeValue;
						}
						
						//get runs
						var Runs = BatsMen[bt].getElementsByTagName('runs');
						if(Runs[0].firstChild) {
							ScoreCard.CurrentScores.BatsMen[bt].Runs = Runs[0].firstChild.nodeValue;
						}
						
						//get balls
						var Balls = BatsMen[bt].getElementsByTagName('balls-faced');
						if(Balls[0].firstChild) {
							ScoreCard.CurrentScores.BatsMen[bt].Balls = Balls[0].firstChild.nodeValue;
						}
						
						//get fours
						var Fours = BatsMen[bt].getElementsByTagName('fours');
						if(Fours[0].firstChild) {
							ScoreCard.CurrentScores.BatsMen[bt].Fours = Fours[0].firstChild.nodeValue;
						}
						
						//get sixes
						var Sixes = BatsMen[bt].getElementsByTagName('sixes');
						if(Sixes[0].firstChild) {
							ScoreCard.CurrentScores.BatsMen[bt].Sixes = Sixes[0].firstChild.nodeValue;
						}
					}
					
					//get bowlers
					var Bowlers = CurrentScore[0].getElementsByTagName('bowler');
					for(var bw = 0; bw < Bowlers.length; bw++) {
						//get full name
						var FullName = Bowlers[bw].getElementsByTagName('name');
						if(FullName[0].firstChild) {
							ScoreCard.CurrentScores.Bowlers[bw].FullName = FullName[0].firstChild.nodeValue;
						}
						
						//get runs
						var Runs = Bowlers[bw].getElementsByTagName('runs');
						if(Runs[0].firstChild) {
							ScoreCard.CurrentScores.Bowlers[bw].Runs = Runs[0].firstChild.nodeValue;
						}
						
						//get overs
						var Overs = Bowlers[bw].getElementsByTagName('overs');
						if(Overs[0].firstChild) {
							ScoreCard.CurrentScores.Bowlers[bw].Overs = Overs[0].firstChild.nodeValue;
						}
						
						//get maidens
						var Maidens = Bowlers[bw].getElementsByTagName('maidens');
						if(Maidens[0].firstChild) {
							ScoreCard.CurrentScores.Bowlers[bw].Maidens = Maidens[0].firstChild.nodeValue;
						}
						
						//get wickets
						var Wickets = Bowlers[bw].getElementsByTagName('wickets');
						if(Wickets[0].firstChild) {
							ScoreCard.CurrentScores.Bowlers[bw].Wickets = Wickets[0].firstChild.nodeValue;
						}
					}
					
					var MaxOvers = CurrentScore[0].getElementsByTagName('maxovers');
					if(MaxOvers[0].firstChild) { 
						ScoreCard.CurrentScores.MaxOvers = MaxOvers[0].firstChild.nodeValue;
					}
						
					//get Target
					var Target = CurrentScore[0].getElementsByTagName('target');
					if(Target[0].firstChild) { 
						ScoreCard.CurrentScores.Target = Target[0].firstChild.nodeValue;
					}
						
					//get Required Runrate
					if('ODI' == Match.Type && '' != ScoreCard.CurrentScores.Target) {
						//TODO = redo overs .6
						var MaxOvers = parseFloat(ScoreCard.CurrentScores.MaxOvers);
						//var MaxOvers = 44.4;
						var MaxBallsDec = Math.round((MaxOvers - Math.floor(MaxOvers)) * 10);						
						var MaxBalls = (Math.round(Math.floor(MaxOvers))  * 6) + MaxBallsDec;
						
						var CurrentOvers = parseFloat(ScoreCard.CurrentScores.BatTeamOvers);
						var CurretBallsDec = Math.round((CurrentOvers - Math.floor(CurrentOvers)) * 10);	
						var CurrentBalls = (Math.round(Math.floor(CurrentOvers))  * 6) + CurretBallsDec;
						
						var BallsMissing = MaxBalls - CurrentBalls;
						var OversMissingWhole = Math.floor(BallsMissing/6);
						var BallsLeftWithoutOvers = BallsMissing - (OversMissingWhole * 6);
						//to get real overs missing divide the decimal part 
						var OversMissing = OversMissingWhole + (BallsLeftWithoutOvers/6);

						//var OversMissing = parseFloat(ScoreCard.CurrentScores.MaxOvers) - parseFloat(ScoreCard.CurrentScores.BatTeamOvers);
						var RunsMissing = parseInt(ScoreCard.CurrentScores.Target) - parseInt(ScoreCard.CurrentScores.BatTeamRuns);
						if(0 !== RunsMissing ) {
							ScoreCard.CurrentScores.RequiredRunRate = Math.round(RunsMissing/OversMissing * 100)/100;
						} else {
							
						}
					} 
					
					//check revised
					var Revised = CurrentScore[0].getElementsByTagName('Revised');
					if(0 < Revised.length) {
						ScoreCard.CurrentScores.Revised = { RevisedOvers: '', RevisedRuns: '', Reason: ''};
						//get overs
						var RevisedOvers = Revised[0].getElementsByTagName('revisedovers');
						if(RevisedOvers[0].firstChild) {
							ScoreCard.CurrentScores.Revised.RevisedOvers = RevisedOvers[0].firstChild.nodeValue;
						}
						
						//get runs
						var RevisedRuns = Revised[0].getElementsByTagName('revisedruns');
						if(RevisedRuns[0].firstChild) {
							ScoreCard.CurrentScores.Revised.RevisedRuns = RevisedRuns[0].firstChild.nodeValue;
						}
						
						//get Reason
						var Reason = Revised[0].getElementsByTagName('reason');
						if(Reason[0].firstChild) {
							ScoreCard.CurrentScores.Revised.Reason = Reason[0].firstChild.nodeValue;
						}
					}
						
					//get last wicket
					var LastWicket = CurrentScore[0].getElementsByTagName('lastwicket');
					if(0 < LastWicket.length) {
						//get name
						var FullName = LastWicket[0].getElementsByTagName('name');
						if(FullName[0].firstChild) {
							ScoreCard.CurrentScores.LastWicket.FullName = FullName[0].firstChild.nodeValue;
						}
						
						//get runs
						var Runs = LastWicket[0].getElementsByTagName('runs');
						if(Runs[0].firstChild) {
							ScoreCard.CurrentScores.LastWicket.Runs = Runs[0].firstChild.nodeValue;
						}
						//get wicket
						var Wicket = LastWicket[0].getElementsByTagName('wicket-nbr');
						if(Wicket[0].firstChild) {
							ScoreCard.CurrentScores.LastWicket.Wicket = Wicket[0].firstChild.nodeValue;
						}
					}
						
					//get Extras
					var Extras = CurrentScore[0].getElementsByTagName('extras');
					if(0 < Extras.length) {
						//get byes
						var Byes = Extras[0].getElementsByTagName('byes');
						if(Byes[0].firstChild) {
							ScoreCard.CurrentScores.Extras.Byes = Byes[0].firstChild.nodeValue;
						}
						
						//get wides
						var Wides = Extras[0].getElementsByTagName('wides');
						if(Wides[0].firstChild) {
							ScoreCard.CurrentScores.Extras.Wides = Wides[0].firstChild.nodeValue;
						}

						//get noballs
						var NoBalls = Extras[0].getElementsByTagName('noballs');
						if(NoBalls[0].firstChild) {
							ScoreCard.CurrentScores.Extras.NoBalls = NoBalls[0].firstChild.nodeValue;
						}
						
						//get legbyes
						var LegByes = Extras[0].getElementsByTagName('legbyes');
						if(LegByes[0].firstChild) {
							ScoreCard.CurrentScores.Extras.LegByes = LegByes[0].firstChild.nodeValue;
						}	
						
						//get penalty
						var Penalty = Extras[0].getElementsByTagName('penalty');
						if(Penalty[0].firstChild) {
							ScoreCard.CurrentScores.Extras.Penalty = Penalty[0].firstChild.nodeValue;
						}	
						
						//get total
						var Total = Extras[0].getElementsByTagName('total');
						if(Total[0].firstChild) {
							ScoreCard.CurrentScores.Extras.Total = Total[0].firstChild.nodeValue;
						}		
						
					}
					
				}
				/*******************************/
																							
					var Innings = response.getElementsByTagName('innings');
					for(var inn = 0; inn < Innings.length; inn ++) {
						var InningsNum = Innings[inn].getAttribute('no');
						ScoreCard.Innings[InningsNum] = {TotalRuns: '', 
												TotalWickets: '', 
												TotalOvers: '', 
												Declared: '', 
												FollowOn: '',
												BatTeam: {TeamNum: 0, Players: [], Captain: '', Keeper: ''}, 
												FallOfWickets: [], 
												Extras: {Byes: '', Wides: '', NoBalls: '', LegByes: '', Penalty: '', Total: ''},
												BowlTeam: {TeamNum: 0, Players: [], Captain: '', Keeper: ''}};
												
						//get runs
						var TotalRuns = Innings[inn].getElementsByTagName('totalruns');
						if(TotalRuns[0].firstChild) {
							ScoreCard.Innings[InningsNum].TotalRuns = TotalRuns[0].firstChild.nodeValue;
						}	
						//get wickets
						var TotalWickets = Innings[inn].getElementsByTagName('totalwickets');
						if(TotalWickets[0].firstChild) {
							ScoreCard.Innings[InningsNum].TotalWickets = TotalWickets[0].firstChild.nodeValue;
						}
						//get overs
						var TotalOvers = Innings[inn].getElementsByTagName('totalovers');
						if(TotalOvers[0].firstChild) {
							ScoreCard.Innings[InningsNum].TotalOvers = TotalOvers[0].firstChild.nodeValue;
						}
						//get declared
						var Declared = Innings[inn].getElementsByTagName('declared');
						if(Declared[0].firstChild) {
							ScoreCard.Innings[InningsNum].Declared = Declared[0].firstChild.nodeValue;
						}
						//get followon
						var FollowOn = Innings[inn].getElementsByTagName('followon');
						if(FollowOn[0].firstChild) {
							ScoreCard.Innings[InningsNum].FollowOn = FollowOn[0].firstChild.nodeValue;
						}
						
						//get fallofwickets
						var FallOfWickets = Innings[inn].getElementsByTagName('fallofwickets');
						if(0 < FallOfWickets.length) {
							var Wickets = FallOfWickets[0].getElementsByTagName('wicket');
							for(var w = 0; w < Wickets.length; w++) {
								var WicketObject = {Nbr: '', Runs: '', Overs: '', BatsMan: ''};
								
								//get Nbr
								var Nbr = Wickets[w].getElementsByTagName('nbr');
								if(Nbr[0].firstChild) {
									WicketObject.Nbr = Nbr[0].firstChild.nodeValue;
								}
								
								//get Runs
								var Runs = Wickets[w].getElementsByTagName('runs');
								if(Runs[0].firstChild) {
									WicketObject.Runs = Runs[0].firstChild.nodeValue;
								}
								
								//get Overs
								var Overs = Wickets[w].getElementsByTagName('overs');
								if(Overs[0].firstChild) {
									WicketObject.Overs = Overs[0].firstChild.nodeValue;
								}
								
								//get BatsMan
								var BatsMan = Wickets[w].getElementsByTagName('batsman');
								if(BatsMan[0].firstChild) {
									WicketObject.BatsMan = BatsMan[0].firstChild.nodeValue;
								}
								
								ScoreCard.Innings[InningsNum].FallOfWickets.push(WicketObject);
							}
						}
						
						//get Extras
						var Extras = Innings[inn].getElementsByTagName('extras');
						if(0 < Extras.length) {
							//Extras: {Byes: '', Wides: '', NoBalls: '', LegByes: '', Penalty: '', Total: ''}
							
							//get Byes
							var Byes = Extras[0].getElementsByTagName('byes');
							if(Byes[0].firstChild) {
								ScoreCard.Innings[InningsNum].Extras.Byes = Byes[0].firstChild.nodeValue;
							}
							//get wides
							var Wides = Extras[0].getElementsByTagName('wides');
							if(Wides[0].firstChild) {
								ScoreCard.Innings[InningsNum].Extras.Wides = Wides[0].firstChild.nodeValue;
							}
							//get noballs
							var NoBalls = Extras[0].getElementsByTagName('noballs');
							if(NoBalls[0].firstChild) {
								ScoreCard.Innings[InningsNum].Extras.NoBalls = NoBalls[0].firstChild.nodeValue;
							}
							//get legbyes
							var LegByes = Extras[0].getElementsByTagName('legbyes');
							if(LegByes[0].firstChild) {
								ScoreCard.Innings[InningsNum].Extras.LegByes = LegByes[0].firstChild.nodeValue;
							}
							//get penalty
							var Penalty = Extras[0].getElementsByTagName('penalty');
							if(Penalty[0].firstChild) {
								ScoreCard.Innings[InningsNum].Extras.Penalty = Penalty[0].firstChild.nodeValue;
							}
							//get total
							var Total = Extras[0].getElementsByTagName('total');
							if(Total[0].firstChild) {
								ScoreCard.Innings[InningsNum].Extras.Total = Total[0].firstChild.nodeValue;
							}
						}	
						
						//get batteam			
						var BatTeam = Innings[inn].getElementsByTagName('batteam');	
						if(0 < BatTeam.length) {
							//find team num
							var TeamName = BatTeam[0].getAttribute('name');
							if(ForComparing.Teams[2].fullname == TeamName) {
								ScoreCard.Innings[InningsNum].BatTeam.TeamNum = 2;
							}
							else if(ForComparing.Teams[1].fullname == TeamName) {
								ScoreCard.Innings[InningsNum].BatTeam.TeamNum = 1;
							} else {
								ScoreCard.Innings[InningsNum].BatTeam.TeamNum = 0;
							}
							
							//get players
							var Players = BatTeam[0].getElementsByTagName('player');
							for(var p = 0; p < Players.length; p++) {
								var PlayerObject = {FullName: '', Captain: '', Keeper: '', Runs: '', Balls: '', Fours: '', Sixes: '', Status: '', OutDescription: ''};
								
								//get Name
								var FullName = Players[p].getElementsByTagName('name');
								if(FullName[0].firstChild) {
									PlayerObject.FullName = FullName[0].firstChild.nodeValue;
								}
								
								//get captain
								var Captain = Players[p].getElementsByTagName('captain');
								if(Captain[0].firstChild) {
									PlayerObject.Captain = Captain[0].firstChild.nodeValue;
								}
								
								//get keeper
								var Keeper = Players[p].getElementsByTagName('keeper');
								if(Keeper[0].firstChild) {
									PlayerObject.Keeper = Keeper[0].firstChild.nodeValue;
								}
								
								//get runs
								var Runs = Players[p].getElementsByTagName('runs');
								if(Runs[0].firstChild) {
									PlayerObject.Runs = Runs[0].firstChild.nodeValue;
								}
								
								//get balls
								var Balls = Players[p].getElementsByTagName('balls');
								if(Balls[0].firstChild) {
									PlayerObject.Balls = Balls[0].firstChild.nodeValue;
								}
								
								//get fours
								var Fours = Players[p].getElementsByTagName('fours');
								if(Fours[0].firstChild) {
									PlayerObject.Fours = Fours[0].firstChild.nodeValue;
								}
								
								//get sixes
								var Sixes = Players[p].getElementsByTagName('sixes');
								if(Sixes[0].firstChild) {
									PlayerObject.Sixes = Sixes[0].firstChild.nodeValue;
								}
								
								//get status
								var Status = Players[p].getElementsByTagName('status');
								if(Status[0].firstChild) {
									PlayerObject.Status = Status[0].firstChild.nodeValue;
								}
								
								//get outdecription
								var OutDescription = Players[p].getElementsByTagName('outdescription');
								if(OutDescription[0].firstChild) {
									PlayerObject.OutDescription = OutDescription[0].firstChild.nodeValue;
								}
								
								if('yes' == PlayerObject.Captain) {
									ScoreCard.Innings[InningsNum].BatTeam.Captain = PlayerObject;
								}
								
								if('yes' == PlayerObject.Keeper) {
									ScoreCard.Innings[InningsNum].BatTeam.Keeper = PlayerObject;
								}
								
								ScoreCard.Innings[InningsNum].BatTeam.Players.push(PlayerObject);
							}
						}	
								
						//get bowlteam				
						var BowlTeam = Innings[inn].getElementsByTagName('bowlteam');		
						if(0 < BowlTeam.length) {
							//find team num
							
							var TeamName = BowlTeam[0].getAttribute('name');
							if(ForComparing.Teams[2].fullname == TeamName) {
								ScoreCard.Innings[InningsNum].BowlTeam.TeamNum = 2;
							}
							else if(ForComparing.Teams[1].fullname == TeamName) {
								ScoreCard.Innings[InningsNum].BowlTeam.TeamNum = 1;
							} else {
								ScoreCard.Innings[InningsNum].BowlTeam.TeamNum = 0;
							}

							//get players
							var Players = BowlTeam[0].getElementsByTagName('player');
							for(var p = 0; p < Players.length; p++) {
								var PlayerObject = {FullName: '', Captain: '', Keeper: '', Overs: '', Maidens: '', RunsOff: '', Wickets: '', Wides: '', NoBalls: ''};
								
								//get Name
								var FullName = Players[p].getElementsByTagName('name');
								if(FullName[0].firstChild) {
									PlayerObject.FullName = FullName[0].firstChild.nodeValue;
								}
								
								//get captain
								var Captain = Players[p].getElementsByTagName('captain');
								if(Captain[0].firstChild) {
									PlayerObject.Captain = Captain[0].firstChild.nodeValue;
								}
								
								//get keeper
								var Keeper = Players[p].getElementsByTagName('keeper');
								if(Keeper[0].firstChild) {
									PlayerObject.Keeper = Keeper[0].firstChild.nodeValue;
								}
								
								//get overs
								var Overs = Players[p].getElementsByTagName('overs');
								if(Overs[0].firstChild) {
									PlayerObject.Overs = Overs[0].firstChild.nodeValue;
								}
								
								//get maidens
								var Maidens = Players[p].getElementsByTagName('maidens');
								if(Maidens[0].firstChild) {
									PlayerObject.Maidens = Maidens[0].firstChild.nodeValue;
								}
								
								//get runsoff
								var RunsOff = Players[p].getElementsByTagName('runsoff');
								if(RunsOff[0].firstChild) {
									PlayerObject.RunsOff = RunsOff[0].firstChild.nodeValue;
								}
								
								//get wickets
								var Wickets = Players[p].getElementsByTagName('wickets');
								if(Wickets[0].firstChild) {
									PlayerObject.Wickets = Wickets[0].firstChild.nodeValue;
								}
								
								//get wides
								var Wides = Players[p].getElementsByTagName('wides');
								if(Wides[0].firstChild) {
									PlayerObject.Wides = Wides[0].firstChild.nodeValue;
								}
								
								//get noballs
								var NoBalls = Players[p].getElementsByTagName('noballs');
								if(NoBalls[0].firstChild) {
									PlayerObject.NoBalls = NoBalls[0].firstChild.nodeValue;
								}
								
								if('yes' == PlayerObject.Captain) {
									ScoreCard.Innings[InningsNum].BowlTeam.Captain = PlayerObject;
								}
								
								if('yes' == PlayerObject.Keeper) {
									ScoreCard.Innings[InningsNum].BowlTeam.Keeper = PlayerObject;
								}
								
								ScoreCard.Innings[InningsNum].BowlTeam.Players.push(PlayerObject);
							}
						}								
					}
					
					//prepare agregates
					/*	Aggregate: [{Batsmen: [], 
									Bowlers: [], 
									BatsmenSorted:[], 
									BowlersSorted: [], 
									TotalOvers: 0, 
									TotalRuns: 0, 
									TotalWickets: 0 },
									{Batsmen: [], Bowlers: [], BatsmenSorted:[], BowlersSorted: [], TotalOvers: 0, TotalRuns: 0, TotalWickets: 0 },
									{Batsmen: [], Bowlers: [], BatsmenSorted:[], BowlersSorted: [], TotalOvers: 0, TotalRuns: 0, TotalWickets: 0 }]*/
					
					for(var inn = 1; inn < ScoreCard.Innings.length; inn++) {
						var Innings = ScoreCard.Innings[inn];
						//for batters
						var AggNum = Innings.BatTeam.TeamNum;
						ScoreCard.Aggregate[AggNum].TotalOvers += parseFloat(Innings.TotalOvers);
						ScoreCard.Aggregate[AggNum].TotalWickets += parseInt(Innings.TotalWickets);
						ScoreCard.Aggregate[AggNum].TotalRuns += parseInt(Innings.TotalRuns);
						
						//add innings num
						ScoreCard.Aggregate[AggNum].InningsNum.push(inn);
						
						
						for(var p = 0; p < Innings.BatTeam.Players.length; p++) {
							ScoreCard.Aggregate[AggNum].Batsmen.push(Innings.BatTeam.Players[p]);
						}
						
						var AggNum = Innings.BowlTeam.TeamNum;
						for(var p = 0; p < Innings.BowlTeam.Players.length; p++) {
							ScoreCard.Aggregate[AggNum].Bowlers.push(Innings.BowlTeam.Players[p]);
							var RankingCoef = (0 < parseInt(ScoreCard.Aggregate[AggNum].Bowlers[p].Wickets)) ? parseInt(ScoreCard.Aggregate[AggNum].Bowlers[p].RunsOff) / parseInt(ScoreCard.Aggregate[AggNum].Bowlers[p].Wickets): (parseInt(ScoreCard.Aggregate[AggNum].Bowlers[p].RunsOff)/0.1);
							if(0 === parseInt(ScoreCard.Aggregate[AggNum].Bowlers[p].Wickets) && 0 === parseInt(ScoreCard.Aggregate[AggNum].Bowlers[p].RunsOff)) {
								RankingCoef = 1000;
							}
							ScoreCard.Aggregate[AggNum].Bowlers[p].RankingCoef = RankingCoef;
						}
						
					}
					
					//sort out the overs.
					var MaxOversDecimal = 0.6;
					ScoreCard.Aggregate[1].TotalOvers = Math.round(ScoreCard.Aggregate[1].TotalOvers * 100) /100;
					DecimalPart1 = ScoreCard.Aggregate[1].TotalOvers - Math.floor(ScoreCard.Aggregate[1].TotalOvers);
					if(DecimalPart1 >= MaxOversDecimal) {
						ScoreCard.Aggregate[1].TotalOvers = Math.floor(ScoreCard.Aggregate[1].TotalOvers) + 1 + (DecimalPart1 - MaxOversDecimal);
					}
					//if(ScoreCard.Aggregate[1].TotalOvers - Math.)
					ScoreCard.Aggregate[2].TotalOvers = Math.round(ScoreCard.Aggregate[2].TotalOvers * 100) /100;
					DecimalPart2 = ScoreCard.Aggregate[2].TotalOvers - Math.floor(ScoreCard.Aggregate[2].TotalOvers);
					if(DecimalPart2 >= MaxOversDecimal) {
						ScoreCard.Aggregate[2].TotalOvers = Math.floor(ScoreCard.Aggregate[2].TotalOvers) + 1 + (DecimalPart2 - MaxOversDecimal);
					}
					
					//now sort
					ScoreCard.Aggregate[1].BatsmenSorted = ScoreCard.Aggregate[1].Batsmen.sort(Cricket.Data.sortByRuns);
					ScoreCard.Aggregate[1].BatsmenSorted = ScoreCard.Aggregate[1].BatsmenSorted.reverse();
					ScoreCard.Aggregate[2].BatsmenSorted = ScoreCard.Aggregate[2].Batsmen.sort(Cricket.Data.sortByRuns);
					ScoreCard.Aggregate[2].BatsmenSorted = ScoreCard.Aggregate[2].BatsmenSorted.reverse();
					
					ScoreCard.Aggregate[1].BowlersSorted = ScoreCard.Aggregate[1].Bowlers.sort(Cricket.Data.sortByWicketsRuns);
					//ScoreCard.Aggregate[1].BowlersSorted = ScoreCard.Aggregate[1].BowlersSorted.reverse();
					ScoreCard.Aggregate[2].BowlersSorted = ScoreCard.Aggregate[2].Bowlers.sort(Cricket.Data.sortByWicketsRuns);
					//ScoreCard.Aggregate[2].BowlersSorted = ScoreCard.Aggregate[2].BowlersSorted.reverse();
					

					ForObject.ParsedFeed[MatchNum].ScoreCard = ScoreCard;
					ForObject.ParsedFeed[MatchNum].ScoreCardLoaded = true;						

					if(typeof CallBack == 'function') {
						CallBack(CallBackParams);
					}

				}
			});
			
			
		} else {
			ForObject.ParsedFeed[MatchNum].ScoreCard = false;
			ForObject.ParsedFeed[MatchNum].ScoreCardLoaded = true;
			if(typeof CallBack == 'function') {
				CallBack(CallBackParams);
			}
		}				
	},
	sortByRuns: function(a, b) {
		if(a.Runs && b.Runs) {
			return parseInt(a.Runs) - parseInt(b.Runs); 
		} else {
			return 0;
		}
	},
	sortByWicketsRuns: function(a, b) {
		if(a.RankingCoef && b.RankingCoef) {
			
			var diff = (a.RankingCoef - b.RankingCoef);
			return diff; 
		} else {
			return 0;
		}
	}
}